<template>
	<view class="shoppingCart">
		<view  v-if="$store.getters.token||userInfo.uid">
			<view class="box">
				<view>申请</view>
				<view class="box_word">代理</view>
			</view> 
			<view class="box">
				<view>名称</view>
				<view class="box_word">
					<input placeholder="请输入" type="text" v-model="form.name" />
				</view>
			</view>
			<view class="box">
				<view>地址</view>
				<view class="box_word">
					<input placeholder="请输入" type="text" v-model="form.address" />
				</view>
			</view>
			<view class="box">
				<view>电话</view>
				<view class="box_word">
					<input placeholder="请输入" type="text" v-model="form.phone" />
				</view>
			</view>

			<view class="btnd" @click="sqbtn">
				申请
			</view>
			<view class="btnx" @click="goback">
				返回
			</view>
		</view>


		<Authorization v-else />
	</view>

</template>

<script>
	import {
		handleUrlParam
	} from '@/utils'
	import {
		jxsInfodealer
	} from "../../../api/order.js"
	import {
		mapGetters,
	} from 'vuex'
	import {
		login,
		authorize
	} from '@/utils'
		import Authorization from "@/pages/authorization/index";
	export default {
		data() {
			return {
				form: {
					pid: "",
					name: "",
					address: "",
					phone: "",
				},
			} 
		},
		components: {
			Authorization
		},

		computed: mapGetters(["userInfo", "token"]),
		onLoad(options) {
			this.form.pid = handleUrlParam(decodeURIComponent(options.q)).pid
		},
		onShow() {
			this.form.pid = this._route.query.pid
		},
		methods: {
			sqbtn() {
				if (this.form.name == '') {
					uni.showToast({
						title: "名称必填",
						icon: "none",
						duration: 2000
					})
					return
				}
				if (!(/^[1]([3-9])[0-9]{9}$/.test(this.form.phone))) {
					uni.showToast({
						title: "电话不正确",
						icon: "none",
						duration: 2000
					})
					return
				}
				jxsInfodealer(this.form).then(res => {
					if (res.status != 200) {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						})
					} else {
						uni.showToast({
							title: "申请成功",
							icon: 'none',
							duration: 2000
						})
						uni.switchTab({
							url:"/pages/home/index"
						}) 
					}
				})
			},
			goback() {
				uni.switchTab({
					url: "/pages/home/index"
				})
			},
		}
	}
</script>

<style scoped lang="less">
	.test {
		overflow: auto;
		border-bottom: 1upx solid #000000;
	}

	.box {

		width: 690upx;
		height: 70upx;
		margin: 0 auto;
		display: flex;
		justify-content: space-between;
		text-align: center;
		border-bottom: 1px solid rgba(0, 0, 0, 0.1);
		margin-top: 30upx;
	}

	.box_word {
		font-size: 17 upx;

		input {
			width: 100%;
			text-align: right;
		}

		// color: #0000004D;


	}

	.bzitem {
		width: 690upx;
		height: 270upx;
		margin: 0 auto;
		background-color: #EFEFF4;
		color: #282828;
		padding: 20upx;
	}

	.btnd {
		width: 300upx;
		height: 70upx;
		margin: 20upx auto;
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: #07c160;
		border-radius: 20upx;
		color: #FFFFFF;
	}

	.btnx {

		width: 300upx;
		height: 70upx;
		margin: 10upx auto;
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: #ff0000;
		border-radius: 20upx;
		color: #FFFFFF;
	}
</style>
